feat(extract): add regex-based R (.r/.R) extractor (#1689)#1759
Open
Sanjays2402 wants to merge 1 commit into
Open
feat(extract): add regex-based R (.r/.R) extractor (#1689)#1759Sanjays2402 wants to merge 1 commit into
Sanjays2402 wants to merge 1 commit into
Conversation
648c4cd to
70159a1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a real extractor for R (
.r/.R), resolving the actionable half of #1689: R files were classified as code (.ris inCODE_EXTENSIONS) but had no extractor wired into_DISPATCH, so every R file silently contributed zero nodes to the graph. The#1689warning (already at HEAD) surfaced the gap; this PR closes it.Why regex, not tree-sitter
Unlike every other language graphify depends on, there is no standalone
tree-sitter-rdistribution on PyPI (tree-sitter-r/tree-sitter-rlangboth 404; verified via the PyPI JSON API andpip index). The only pip-installable R grammar is the ~165-grammartree-sitter-language-pack, which cuts hard against this repo's one-dedicated-wheel-per-language convention.So this follows the existing regex-fallback precedent already used for Pascal (#781) and the non-tree-sitter path for DM (#1104): a self-contained, zero-dependency regex extractor in
graphify/extractors/r.py.pyproject.tomlis untouched — no new dependency.An AST-quality upgrade is a clean future follow-up if/when a standalone R grammar wheel becomes available; the module is structured so that swap is localized.
What it extracts
f <- function(x),g = function(x),h <<- function(),k <- \(x) xcontainsnode/edgelibrary(dplyr),require(ggplot2),requireNamespace(...),loadNamespace(...)imports(context=import)source("helpers.R")imports(context=import)setClass("Circle", ...),setRefClass(...)containsnodesetClass("Circle", contains = "Shape")inheritsedgesetGeneric("area", ...)containsnodesetMethod("area", "Circle", ...)methodedge (class → method)calls(context=call)The extractor is string- and comment-aware (a
#inside a string literal is not a comment; braces/parens inside strings don't affect body-span matching), and skips accessor/namespace-qualified call targets (obj$m(),obj@m(),pkg::fn()) so only genuine local free-function calls becomecallsedges.Wiring
graphify/extractors/r.py— new module (mirrorsextractors/elixir.pylayout, reusesbase.pyhelpers_make_id/_file_stem).extract.py— import + re-exportextract_r;.r/.R→_DISPATCH; language-name map entry;Rscript→_SHEBANG_DISPATCH(so#!/usr/bin/env Rscriptextensionless scripts route correctly); updated the#1689warning comment (it no longer applies to.r).Tests
tests/fixtures/sample.R— new fixture exercising every construct.tests/test_languages.py— 12 new R tests (functions,\(x)lambda, imports incl.source(), S4 classes, inheritance, generics/methods, calls, call-context, no-dangling-edges).tests/test_extract.py— updated the two tests that used.r/.Ras their "code file with no AST extractor" example (that's no longer true) to use.ets(ArkTS), which remains genuinely unsupported.Local run (on
v8):tests/test_languages.py+tests/test_extract.py= 442 passed, 14 skipped, no regressions. The 12 new R tests and the two updated#1689tests all pass.Closes the extractor half of #1689.